package edu.hunau.cxb19.oop.class21;

import java.util.List;

import org.junit.Test;

import edu.hunau.cxb19.oop.class21.lambda.AppleFilter;

/**
 *
 * @author hb
 *
 *         2020-03-24 16:18:34
 */
public class AppleTest {

	@Test
	public void filterTest() {
		List<Apple> datas = Apple.getDatas();
		// 获得红苹果
		List<Apple> reds = AppleService.filter(datas, new AppleFilter() {
			@Override
			public boolean test(Apple apple) {
				return apple.getColor().equals("red");
			}
		});

		reds = AppleService.filter(datas, (Apple apple) -> {
			return apple.getColor().equals("red");
		});

		reds = AppleService.filter(datas, (apple) -> {
			return apple.getColor().equals("red");
		});
		//如果参数只有一个，可以省略括号
		reds = AppleService.filter(datas, apple -> {
			return apple.getColor().equals("red");
		});
		
		//如果只有一条return语句，那么代码体中的花括号可以省略 ，return关键字必须省略
		reds = AppleService.filter(datas, apple -> apple.getColor().equals("red"));
		
		
		System.out.println(reds);

		// 根据重量进行过滤
		List<Apple> weigths = AppleService.filter(datas, new AppleFilter() {
			@Override
			public boolean test(Apple apple) {
				return apple.getWeight() >= 150;
			}
		});
		weigths = AppleService.filter(datas, apple->apple.getWeight()>=150);
		
		//找到重量超过150克的红苹果
		List<Apple> list=AppleService.filter(datas, apple->apple.getColor().equals("red")&& apple.getWeight()>=150);

		System.out.println(weigths);

	}
}
